package com.egao.common.publicly;

import cn.hutool.core.util.StrUtil;
import com.egao.common.core.web.JsonResult;
import com.egao.common.module.system.service.DictService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 公共字典
 * @author lym
 */
@Api(tags = "公共字典")
@RestController
@RequestMapping("${api}")
public class PubliclyDictController {

    @Autowired
    private DictService dictService;

    @ApiOperation("根据类型查询字典集合")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "type", value = "字典类型", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "label", value = "字典标签(模糊查询,空则查询全部)", required = false, dataType = "string", paramType = "query")
    })
    @GetMapping("/publicly/dict/list")
    public JsonResult list(String type, String label) {
        if (StrUtil.isBlank(label)) {
            return JsonResult.ok().setData(dictService.cacheList(type));
        }
        return JsonResult.ok().setData(dictService.listAll(type, label));
    }

}
